package com.itheima.homework6;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.TreeSet;

public class PaiXu {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        String s1 = "ccbbaa";
        String s2 = "abcd";
        String s3 = "ccc";
        String s4 = "bbb";
        String s5 = "aabbcc";
        String s6 = "aaa";
        list.add(s1);
        list.add(s2);
        list.add(s3);
        list.add(s4);
        list.add(s5);
        list.add(s6);
        /*list.sort((o1,o2)->{
            int result = o1.length()-o2.length();
            result = result == 0?o1.compareTo(o2):result;
            result = result == 0?1:result;
            return result;
        });
        System.out.println(list);*/
        TreeSet<String> set = new TreeSet<>((o1,o2)->{
            int result = o1.length()-o2.length();
            result = result == 0?o1.compareTo(o2):result;
            result = result == 0?1:result;
            return result;
        });
        set.addAll(list);
        list.clear();
        list.addAll(set);
        list.forEach(s-> System.out.println(s));
    }
}
